package com.glodon.paas.job.agent.worker;

import static com.glodon.paas.job.JobConstants.*;
import static org.apache.commons.lang.ArrayUtils.*;

import java.io.File;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

public class WorkerConfig {
    private String type;
    private String cmd;
    private String[] envp;
    private int concurrent = 1;

    public WorkerConfig(String type, String cmd, int concurrent) {
        this.type = type;
        this.concurrent = concurrent;
    }

    public WorkerConfig(String type, String cmd) {
        this.type = type;
        this.cmd = cmd;
    }

    public WorkerConfig(String type, String cmd, String[] envp) {
        this.type = type;
        this.cmd = cmd;
        if (isEmpty(envp)) {
            envp = null;
        } else {
            String classpath = System.getProperty("java.class.path");
            envp = (String[]) ArrayUtils.addAll(envp, StringUtils.split(classpath, File.pathSeparatorChar));
        }
        this.envp = envp;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getCmd() {
        return cmd;
    }

    public void setCmd(String cmd) {
        this.cmd = cmd;
    }

    public String[] getEnvp() {
        return envp;
    }

    public void setEnvp(String[] envp) {
        this.envp = envp;
    }

    public int getConcurrent() {
        return concurrent;
    }

    public void setConcurrent(int concurrent) {
        this.concurrent = concurrent;
    }

    public String getQueueName() {
        return TASK_QUEUE_PREFIX + type;
    }

}
